Class SimplyPresentable::PartialPresenter
In: vendor/plugins/simply_presentable/lib/simply_presentable/presenter/partial.rb
Parent: SimplyPresentable::Presenter

Methods

Constants

RENDER_KEYS = %w{ partial locals status }.map(&:to_sym)

Public Instance methods

Returns the options needed to render this as a partial using renderer.render(options)

Example:

  present(Foo.find(1)).partial_options
  => { :partial => 'foos/show', :foo => the_presented_foo_obj }

Options:

:variable_name:The name the object will be bound to in the rendered template
:partial:The name of the partial file
:partial_dir:The name of the partial directory

If the partial option includes a /, it will be used for the directory and file:

  present(Foo.find(1)).partial_options(:partial => 'bars/baw')
  => { :partial => 'bars/baw', :foo => the_presented_foo_obj }

[Source]

    # File vendor/plugins/simply_presentable/lib/simply_presentable/presenter/partial.rb, line 19
19:   def partial_options(options = {})
20:     options.reverse_deep_merge(
21:       :locals => { partial_variable_name(options) => @presenter_proxy }
22:     ).merge(
23:       :partial => partial_path(options.reverse_deep_merge(:partial => nil))
24:     ).symbolize_keys.delete_unless_keys!(RENDER_KEYS)
25:   end

Calls render on the renderer with the partial_options returned by the calling the partial_options method with the options passed to this method.

[Source]

    # File vendor/plugins/simply_presentable/lib/simply_presentable/presenter/partial.rb, line 29
29:   def render(options = {})
30:     @renderer.render(partial_options(options))
31:   end

Protected Instance methods

[Source]

    # File vendor/plugins/simply_presentable/lib/simply_presentable/presenter/partial.rb, line 39
39:     def partial_dir(options)
40:       options[:partial_dir] || singular_class_name.pluralize
41:     end

[Source]

    # File vendor/plugins/simply_presentable/lib/simply_presentable/presenter/partial.rb, line 43
43:     def partial_file(options)
44:       options[:partial] || 'show'
45:     end

[Source]

    # File vendor/plugins/simply_presentable/lib/simply_presentable/presenter/partial.rb, line 34
34:     def partial_path(options = {})
35:       partial_file = partial_file(options)
36:       partial_file.include?("/") ? partial_file : "#{partial_dir(options)}/#{partial_file}"
37:     end

[Source]

    # File vendor/plugins/simply_presentable/lib/simply_presentable/presenter/partial.rb, line 47
47:     def partial_variable_name(options = {})
48:       (options[:variable_name] || singular_class_name).to_sym
49:     end

[Validate]